<template>
  <div class="systemActive">
    <el-form ref="systemActiveForm" :model="systemActiveForm" :rules="registerRules" class="systemActive-form">
      <h3 class="title">厂网调控监控系统</h3>
      <el-form-item prop="serial">
        <el-input v-model="systemActiveForm.serial" type="text" auto-complete="off" placeholder="请输入序列号">
          <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
        </el-input>
      </el-form-item>
      <el-form-item prop="registration">
        <el-input v-model="systemActiveForm.registration" type="number" auto-complete="off" placeholder="请输入注册码"
          @keyup.enter.native="handleRegister">
          <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
        </el-input>
      </el-form-item>

      <el-form-item style="width:100%;">
        <el-button :loading="loading" size="medium" type="primary" style="width:100%;"
          @click.native.prevent="handleRegister">
          <span v-if="!loading">系 统 激 活</span>
          <span v-else>激 活 中...</span>
        </el-button>
        <div style="float: right;">
          <router-link class="link-type" :to="'/login'">使用已有账户登录</router-link>
        </div>
      </el-form-item>
    </el-form>
    <!--  底部  -->
    <div class="el-systemActive-footer">
      <span>Copyright © 北京慧能分享科技有限公司 All Rights Reserved.</span>
    </div>
  </div>
</template>

<script>
import { getCodeImg, systemActive } from "@/api/login";

export default {
  name: "systemActive",
  data() {

    return {
      codeUrl: "",
      systemActiveForm: {
        username: "",
        password: "",
        confirmPassword: "",
        code: "",
        uuid: ""
      },
      registerRules: {
        serial: [
          { required: true, trigger: "blur", message: "请输入序列号" },
          { min: 2, max: 20, message: '序列号长度必须介于 2 和 20 之间', trigger: 'blur' }
        ],
        registration: [
          { required: true, trigger: "blur", message: "请输入注册码" },
          { min: 5, max: 20, message: '注册码长度必须介于 5 和 20 之间', trigger: 'blur' }
        ]
      },
      loading: false,
    };
  },
  created() {
  },
  methods: {
    handleRegister() {
      this.$refs.systemActiveForm.validate(valid => {
        if (valid) {
          this.loading = true;
          systemActive(this.systemActiveForm).then(res => {
            const username = this.systemActiveForm.username;
            this.$alert("<font color='red'>恭喜你，您的账号 " + username + " 激活成功！</font>", '系统提示', {
              dangerouslyUseHTMLString: true,
              type: 'success'
            }).then(() => {
              this.$router.push("/login");
            }).catch(() => { });
          }).catch(() => {
            this.loading = false;
          })
        }
      });
    }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss">
.systemActive {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  background-image: url("../assets/images/login-background.jpg");
  background-size: cover;
}

.title {
  margin: 0px auto 30px auto;
  text-align: center;
  color: #707070;
  font-size: 16px;
  font-weight: 700;
}

.systemActive-form {
  border-radius: 6px;
  background: #ffffff;
  width: 400px;
  padding: 25px 25px 5px 25px;

  .el-input {
    height: 38px;

    input {
      height: 38px;
    }
  }

  .input-icon {
    height: 39px;
    width: 14px;
    margin-left: 2px;
  }
}

.systemActive-tip {
  font-size: 13px;
  text-align: center;
  color: #bfbfbf;
}

.systemActive-code {
  width: 33%;
  height: 38px;
  float: right;

  img {
    cursor: pointer;
    vertical-align: middle;
  }
}

.el-systemActive-footer {
  height: 40px;
  line-height: 40px;
  position: fixed;
  bottom: 0;
  width: 100%;
  text-align: center;
  color: #fff;
  font-family: Arial;
  font-size: 12px;
  letter-spacing: 1px;
}

.systemActive-code-img {
  height: 38px;
}

.systemActive {
  .link-type {
    display: inline-block;
    font-size: 16px;
    margin: 0px;
  }
}
</style>
